package com.hr.until;

import com.hr.entity.News;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/*
    Created with IntelliJ IDEA.
    @author: wang sir
    Date: 2021/7/19
    Time: 16:01
    To change this template use File | Settings | File Templates.
    Description:封装每页的数量
 */
@Data
@NoArgsConstructor
@AllArgsConstructor

public class PageUtil {
    private Integer pageNo;//当前页面
    private Integer pageSize = Constant.PAGESIZE;//页面大小
    private Integer totalCount;//总记录数
    private Integer totalPageCount; //总页数

    private List<News> newsList;//每页的数据

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
        //计算总页数
        this.totalPageCount = (totalCount % pageSize == 0 ? totalCount /pageSize : totalCount/pageSize+1);
    }

    public void setPageNo(Integer pageNo) {
        if (pageNo > totalPageCount)
            pageNo = totalPageCount;
        this.pageNo = pageNo;
    }
}